package com.example.boardroom.demo;

import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.alibaba.fastjson.JSON;
import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.LogUtils;
import com.example.boardroom.R;
import com.example.boardroom.R2;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.AbsCallback;
import com.lzy.okgo.model.Response;
import com.tencent.smtt.sdk.QbSdk;
import com.tencent.smtt.sdk.WebView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity3 extends BaseActivity {
    Button btn_scanning;
    TextView tv_scxxx;
    @BindView(R2.id.btn_open_4)
    Button btnOpen4;
    @BindView(R2.id.btn_close_4)
    Button btnClose4;
    @BindView(R2.id.btn_open_9)
    Button btnOpen9;
    @BindView(R2.id.btn_close_9)
    Button btnClose9;
    @BindView(R2.id.btn_open_all)
    Button btnOpenAll;
    @BindView(R2.id.btn_close_all)
    Button btnCloseAll;
    private String tag = "lufei_x5";
    private WebView forum_context;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main02);
        ButterKnife.bind(this);

//        AndPermission.with(this)
//                .runtime()
//                .permission(Permission.WRITE_EXTERNAL_STORAGE, Permission.READ_PHONE_STATE).onGranted(new Action<List<String>>() {
//                    @Override
//                    public void onAction(List<String> data) {
//
//                    }
//                }).onDenied(new Action<List<String>>() {
//                    @Override
//                    public void onAction(List<String> data) {
//
//                    }
//                }).start();


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        QbSdk.clearAllWebViewCache(this, true); // 清除缓存

    }

    private void getdata(String groupAddress, String value) {
        DengBean dengBean=new DengBean(groupAddress,value);
        String jsonString2 = JSON.toJSONString(dengBean);
        LogUtils.i("lufei_oop",jsonString2);
        OkGo.<String>post("http://192.168.1.26:19100/link/device/test")
                .tag(this)
//                .upJson(jsonString2)
                .params("groupAddress",groupAddress)
                .params("value",value)
                .execute(new AbsCallback<String>() {
                    @Override
                    public void onSuccess(Response<String> response) {

                    }

                    @Override
                    public String convertResponse(okhttp3.Response response) throws Throwable {
                        return null;
                    }
                });
    }

    @OnClick({R2.id.btn_open_4, R2.id.btn_close_4, R2.id.btn_open_9, R2.id.btn_close_9, R2.id.btn_open_all, R2.id.btn_close_all})
    public void onClick(View view) {
        int viewId = view.getId();
        if (viewId == R.id.btn_open_4) {
            getdata("11/1/3", "1");
        } else if (viewId == R.id.btn_close_4) {
            getdata("11/1/4", "0");
        } else if (viewId == R.id.btn_open_9) {
            getdata("11/1/5", "1");
        } else if (viewId == R.id.btn_close_9) {
            getdata("11/1/6", "0");
        } else if (viewId == R.id.btn_open_all) {
            getdata("11/1/2", "1");
        } else if (viewId == R.id.btn_close_all) {
            getdata("11/1/7", "0");
        }
    }
}
